********************************************************************************
********************************************************************************
** Robustness analysis 2
** Sensitivity to unobserved heterogeneity
********************************************************************************
********************************************************************************

** Load data
use "$dataraw_path\data_ftna_publication.dta", clear


** Oster analysis
qui reg gpa_ftna_core_sd private if sample==1

matrix a = r(table)
local r2_1 = e(r2)

qui areg gpa_ftna_core_sd private female uncommon_name peers_score_core_sd ///
	peers_fail_share peers_as_share gpa_psle_other_sd if sample==1, ///
	cl(school_id) a(group_id)

matrix b = r(table)
local r2_2 = e(r2)

qui psacalc delta private, rmax(0.96018)

file open rob2 using "$out_path\oster_analysis.txt", write replace

file write rob2 "Private school coefficient after Oster adjustment: " ///
	(b[1,1]-(a[1,1]-b[1,1])*(`r2_2'*1.3-`r2_2')/(`r2_2'-`r2_1')) _n ///
	"Relative degree of selection: " (`r(delta)')

file close rob2

